<template>
  <div>
    <el-table
      :data="specsList"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="规格编号"> </el-table-column>
      <el-table-column prop="specsname" label="规格名称"> </el-table-column>
      <el-table-column label="规格属性">
        <template slot-scope="scope">
          <div>
            <el-tag v-for="(item, index) in scope.row.attrs" :key="index">{{
              item
            }}</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button v-if="scope.row.status == 1" type="danger">
              启用
            </el-button>
            <el-button v-else type="success"> 禁用 </el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button @click="dit(scope.row.id)">编辑</el-button>
            <v-del @del="del(scope.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
    
    <el-pagination
      background
      layout="prev, pager, next"
      :total="specstotal"
      :page-size="specssize"
      @current-change="change"
    >
    </el-pagination>
  </div>
</template>
<script>
import { successAlert, warningAlert } from "../../../util/alter";
import { mapGetters, mapActions } from "vuex";
//引入删除接口
import { specsDel } from "../../../requster/api";
import vDel from "../../../components/del.vue";
export default {
  components: {
    vDel,
  },
  data() {
    return {};
  },

  methods: {
    ...mapActions({
      reqspecsList: "specs/reqchangelist",
      reqspecstotal: "specs/reqchangetotal",
      reqspecspage: "specs/reqchangepage",
    }),
    change(num) {
      this.reqspecspage(num);
    },

    // 删除事件
    del(id) {
      console.log(123);
      specsDel({ id: id }).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          //  重新渲染页面
          this.reqspecsList();
        //   重新请求总条数
        this.reqspecstotal()
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
    // 编辑事件
    dit(id) {
      this.$emit("dit", id);
    },
  },

  computed: {
    ...mapGetters({
      specsList: "specs/list",
      specstotal: "specs/total",
      specssize: "specs/size",
    }),
  },
  mounted() {
    this.reqspecstotal();
    this.reqspecspage(1);
  },
};
</script>

<style>
</style>